import { Dispatch } from "redux";
import * as actionType from '../constance'
import {
    getHomeRequest
} from '@/api/request'

export const setRecommendEntrance=(data:any[])=>({
    type:actionType.SET_RECOMMEND_ENTRANCE,
    data
})
export const setRecommendCourse=(data:any[])=>({
    type:actionType.SET_RECOMMEND_COURSE,
    data
})
export const setContentTabs=(data:any[])=>({
    type:actionType.SET_CONTENT_TABS,
    data
})
export const setRecommendVideos=(data:any[])=>({
    type:actionType.SET_RECOMMEND_VIDEOS,
    data
}) 
export const setRecommendLoading=(data:boolean)=>({
    type:actionType.SET_RECOMMEND_LOADING,
    data
})
export const changeRecommendVideoIsFavorites=(index:number)=>({
    type:actionType.SET_VIDEO_ISFAVORITES,
    index
})
export const getHomeRecommendAction=()=>{
    return (dispatch:Dispatch)=>{
        dispatch(setRecommendLoading(true))
        getHomeRequest()
            .then(data=>{
                // console.log(data.data.data)
                const {sections}=data.data.data;
                // console.log(sections[2].listSlide,'===')
                dispatch(setRecommendEntrance(sections[0].quickEntrances))
                dispatch(setRecommendCourse(sections[1].listSlide))
                dispatch(setContentTabs(sections[2].selectorContentTabs))
                dispatch(setRecommendVideos(sections.slice(3)))
            })
    }
}